/**
 * 所有版权归 广西梧州 陈锦韬 所有
 *
 * @Title: CamundaController
 * @Package com.rx.camunda.controller
 * @Description: 流程控制器
 * @author: 陈锦韬
 * @date: 2021\8\14 0014
 * @version V1.0
 * @Copyright: 2021 陈锦韬  All rights reserved.
 */
package com.rx.camunda.controller;

import com.rx.camunda.service.CamundaService;
import com.rx.camunda.vo.ActReProcdef;
import com.rx.camunda.vo.ActRuInstance;
import com.rx.camunda.vo.ActRuOperate;
import com.rx.camunda.vo.ActRuTask;
import com.rx.core.base.RxBaseController;
import com.rx.core.enm.RESULT_CODE;
import com.rx.core.util.RxUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * @author: Administrator
 * @Description: 流程控制器
 * @date: 2021\8\14 0014
 */
@RestController
@RequestMapping("camunda")
@Slf4j
public class CamundaController extends RxBaseController {

    @Autowired
    private CamundaService camundaService;

    /**
     * 流程定义查询
     * @return
     */
    @PostMapping(value = "process-defined/page")
    public Object processDefinedPage(@Valid @RequestBody ActReProcdef data){
        return camundaService.processDefinedPage(data);
    }

    @PostMapping(value = "process-defined/state")
    public Object processDefinedState(@Valid @RequestBody List<ActReProcdef> data){
        return camundaService.processDefinedState(data);
    }

    @PostMapping(value = "process-defined/delete")
    public Object processDefinedDelete(@Valid @RequestBody ActReProcdef data){
        return camundaService.processDefinedDelete(data);
    }

    /**
     * 重新部署
     * @param data
     * @return
     */
    @PostMapping(value = "process-defined/re-deploy")
    public Object processDefinedReDeploy(@Valid @RequestBody ActReProcdef data){
        return camundaService.processDefinedReDeploy(data);
    }

    @GetMapping(value = "process-defined/download")
    public Object processDefinedDownload(@RequestParam("bid") String bid,
                                         @RequestParam("name") String name,
                                         @RequestParam("version") Integer version){

        ActReProcdef data = new ActReProcdef();
        data.setName(name);
        data.setBid(bid);
        data.setVersion(version);
        return camundaService.processDefinedDownload(data);
    }

    @PostMapping(value = "process-defined/upload")
    public Object processDefinedUpload(@RequestParam("file")MultipartFile file){

        RxUtil.CheckUtil.condition(file.isEmpty(), RESULT_CODE.FAIL,"上传失败！");

        return camundaService.processDefinedUpload(file);
    }

    /**
     * 用户节点
     * @param data
     * @return
     */
    @PostMapping(value = "process-defined/task-list")
    public Object processDefinedTaskPage(@Valid @RequestBody ActRuTask data){
        RxUtil.CheckUtil.check(data.getProcessDefinitionId(),RESULT_CODE.MESSAGE,"请输入流程定义ID");
        return camundaService.processDefinedTaskPage(data);
    }
    //////////////////////////////////////////////////////////////////////////////////////

    /**
     * 流程实例分页查询
     * @param data
     * @return
     */
    @PostMapping(value = "process-instance/page")
    public Object processInstancePage(@Valid @RequestBody ActRuInstance data){
        return camundaService.processInstancePage(data);
    }

    /**
     * 待办节点
     * @param data
     * @return
     */
    @PostMapping(value = "process-task/page")
    public Object processTaskPage(@Valid @RequestBody ActRuTask data){
        return camundaService.processTaskPage(data);
    }

    /**
     * 已办流程
     * @param data
     * @return
     */
    @PostMapping(value = "process-done/page")
    public Object processDonePage(@Valid @RequestBody ActRuInstance data){
        return camundaService.processDonePage(data);
    }

    /**
     * 办结流程
     * @param data
     * @return
     */
    @PostMapping(value = "process-finish/page")
    public Object processFinishPage(@Valid @RequestBody ActRuInstance data){
        return camundaService.processFinishPage(data);
    }

    /**
     * 审批通过
     * @param data
     * @return
     */
    @PostMapping(value = "process-op/pass")
    public Object processPass(@Valid @RequestBody ActRuOperate data){
        return camundaService.processPass(data);
    }

    /**
     * 否决
     * @param data
     * @return
     */
    @PostMapping(value = "process-op/reject")
    public Object processReject(@Valid @RequestBody ActRuOperate data){
        return camundaService.processReject(data);
    }

    /**
     * 驳回
     * @param data
     * @return
     */
    @PostMapping(value = "process-op/refuse")
    public Object processRefuse(@Valid @RequestBody ActRuOperate data){
        return camundaService.processRefuse(data);
    }

    /**
     * 撤回
     * @param data
     * @return
     */
    @PostMapping(value = "process-op/cancel")
    public Object processCancel(@Valid @RequestBody ActRuOperate data){
        return camundaService.processCancel(data);
    }
    /**
     * 复活完结的流程
     * @param data
     * @return
     */
    @PostMapping(value = "process-op/redo")
    public Object processRedo(@Valid @RequestBody ActRuOperate data){
        return camundaService.processRedo(data);
    }
}
